// interface 和 type 相类似，但不完全一致
interface Pereson {
  // readonly name: string // 只读不可修改
  name: string
  age?: number // 可有可无
  [propName: string]: any // 额外的属性
  say(): string // 需要有一个方法
}

// 接口继承
interface Teacher extends Pereson {
  teach(): string
}

// 接口直接定义方法类型
interface SayHi {
  (word: string): string
}

const getPersonName = (person: Pereson) => {
  console.log(person.name)
}

const setPersonName = (person: Teacher, name: string): void => {
  person.name = name
}

const person = {
  name: 'zws',
  say() {
    return 'say hello'
  },
  teach() {
    return 'teach'
  }
}

getPersonName(person)
setPersonName(person, 'lin')

// 类使用接口，做属性约束。语法：implements
class User implements Pereson {
  name = 'zws'
  say() {
    return 'hello'
  }
}

const say: SayHi = (word: string) => {
  return word
}
